package org.sdnstproject.interlayer.interlayerProxy;

import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.channel.unix.Socket;

/* - controller log analysis
 * - socket close
 * - receive error msg
 * - has received response msg or not
 * */
public class ResultAnalyzer{
	private static final Logger log = LoggerFactory.getLogger(ResultAnalyzer.class);
	public volatile boolean isSocketClose = false;
	public volatile boolean isControllerException = false;
	public volatile boolean isReceiveErrorMsg = false;
	public volatile boolean notReceiveResponseMsg = false;
	ArrayList<String> controllerException = new ArrayList<String>();
	public String result = "UNKOWN";
	
	public ResultAnalyzer() {
		
	}

	private static class Single{
		private static final ResultAnalyzer instance = new ResultAnalyzer();
	}
	
	public static ResultAnalyzer getInstance() {
		return Single.instance;
	}
	public void init() {
		isSocketClose = false;
		isControllerException = false;
		isReceiveErrorMsg = false;
		notReceiveResponseMsg = false;
		result = "UNKOWN";
		controllerException.clear();
	}
	public String getResult() {
		if(isSocketClose || isControllerException || isReceiveErrorMsg || notReceiveResponseMsg) {
			result = "FAIL";
		}else {
			result = "PASS";
		}
		return result;
	}
	
	@Override
	public String toString() {
		StringBuilder b = new StringBuilder("ResultAnalyzer(");
		b.append("result : ").append(result).append(", ");
		if(isSocketClose) b.append("socket is closed; ");
		if(isReceiveErrorMsg) b.append("receive error message; ");
		if(notReceiveResponseMsg) b.append("controller do not reply; ");
		if(isControllerException) {
			b.append("controler occur exceptioins : ");
			b.append(controllerException.toString());
		}
		b.append(")");
		return b.toString();
	}

}
